// 两数之和
var twoSum = function (nums, target) {
  let result = []
  for (let i = 0; i < nums.length; i++) {
    let dValue = target - nums[i] // 获取差值
    let nowIndex = nums.indexOf(nums[i]) // 获取当前数值下标
    let dIndex = nums.indexOf(dValue, nowIndex + 1) // 判断差值是否存在于目标数组
    console.log('dIndex', dIndex)
    if (dIndex > -1 && nowIndex !== dIndex) {  // 差值存在于目标数组
      let alreadyIn = result.indexOf(dIndex) > -1 ? true : false
      if (!alreadyIn) { // 且没有被使用过
        result.push(nowIndex)
        result.push(dIndex)
      }
    }
  }
  return result
}
console.log(twoSum([3, 3], 6))
// console.log(twoSum([2, 7, 11, 15], 9))
// console.log(twoSum([3, 2, 4], 6))